/**

 */

package com.bda.mediatheque.controller;

import com.bda.mediatheque.service.ImplUtilisateurDao;
import com.bda.mediatheque.service.Test;
import java.io.*;
import java.util.List;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;


/**
 * The servlet class to list Users from database
 */
@WebServlet(name="ListUserServlet", urlPatterns={"/ListUser"})
public class ListUserServlet extends HttpServlet {
    
  
    
    /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

        try {
           

            //query for all the users in database
            ImplUtilisateurDao utilisateurDao = new ImplUtilisateurDao();
            List users = utilisateurDao.findAll();
            // attach the result to the request
            request.setAttribute("userList",users);
            
            //Forward to the jsp page for rendering : transfer le controle vers la page ListUser.jsp
            request.getRequestDispatcher("ListUser.jsp").forward(request, response);
            
        } catch (Exception ex) {
            throw new ServletException(ex);
        } finally {
        
        }
      
    }
    
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
    
    /** Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
    
    /** Returns a short description of the servlet.
     */
    public String getServletInfo() {
        return "ListUser servlet";
    }
    // </editor-fold>
}
